package com.che.libcommon.widget.viewpager;

import java.util.ArrayList;
import java.util.List;

public abstract class InfiniteLoopAdapter<T> extends RecyclingPagerAdapter{
  private List<T> datas = new ArrayList<T>();

  private int size;

  private int itemSize = Integer.MAX_VALUE;

  public void setData(List<T> data) {
    datas.clear();
    if(data != null){
      this.datas.addAll(data);
    }
    size = datas.size();
    if (size == 1){
      itemSize = 1;
    }
  }

  @Override
  public final int getCount() {
    return itemSize;
  }

  public int getDataSize(){
    return size;
  }

  public int getPosition(int adapterPosition) {
    return  adapterPosition % size;
  }

  public T getItem(int adapterPosition){
    return datas.get(getPosition(adapterPosition));
  }

}
